package com.bible.fire.local;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;

public class RuntimeContext {
	
	private static List<WeakReference<Activity>> activityList = new ArrayList<WeakReference<Activity>>();
	
	private static ThreadPool httpPool;

	public static void addRuntimeActivity( Activity activity ){
		if( activity != null ){
			activityList.add( new WeakReference( activity ) );
		}
	}
	
	// 自定义方法，关闭当前打开的所有avtivity然后再杀掉进程
	public static void  finishRuntimeApp(){
		for( WeakReference<Activity> wr : activityList ){
			if( wr != null && wr.get() != null ){
				wr.get().finish();
			}
		}
		if( httpPool != null ){
			httpPool.destroyNow();
		}
		android.os.Process.killProcess( android.os.Process.myPid() );
	}
	
	public static ThreadPool getHttpThreadPool(){
		if( httpPool == null ){
			httpPool = ThreadPool.getThreadPool( 5 );
		}
		return httpPool;
	}
}
